package com.liu.nb.controller;


import com.liu.nb.entity.Receiptdebug;
import com.liu.nb.util.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * <p>
 * 消缺任务回执表 前端控制器
 * </p>
 *
 * @author liuziyi
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/nb/receiptdebug")
public class ReceiptdebugController extends BaseController{


    /**
     * 消缺任务消缺员回执录入和管理员审核，
     * @param receiptdebug
     * @param principal
     * @return
     */
    @PreAuthorize("hasAnyRole('xianluadmin','xiaoqueyuan')")
    @PostMapping("/saveReceiptDeBug")
    public Result saveReceiptDeBug(Receiptdebug receiptdebug, Principal principal){
        Integer id = (iUserService.getByUsername(principal.getName())).getId();
        String name = principal.getName();
        String substring = name.substring(0, 3);
        if(substring.equals("adm")){
            boolean save = receiptdebugService.save(receiptdebug);
            return Result.success(save);
        }else if(substring.equals("xun")){
            receiptdebug.setUid(id);
            boolean save = receiptdebugService.save(receiptdebug);
            return Result.success(save);
        }
        return null;
    }
}
